package main

import (
	"fmt"
	"go_study/top/jacktgq/functional/tree"
)

// 组合方式的扩展
type myTreeNode struct {
	node *tree.Node
}

func (myNode *myTreeNode) postOrderTraverse() {
	if myNode != nil && myNode.node != nil {
		leftChild := myTreeNode{myNode.node.Left}
		leftChild.postOrderTraverse()
		rightChild := myTreeNode{myNode.node.Right}
		rightChild.postOrderTraverse()
		myNode.node.Print()
	}
}

func main() {
	var root = tree.Node{Value: 3}
	root.Left = &tree.Node{}
	root.Right = &tree.Node{5, nil, nil}
	root.Right.Left = new(tree.Node)
	root.Left.Right = tree.CreateNode(6)
	fmt.Println(root)
	fmt.Println(root.Right)
	fmt.Println(root.Right.Left)

	root.PreOrderTraverse()
	fmt.Println()
	node := myTreeNode{&root}
	node.postOrderTraverse()
	fmt.Println()

	nodeCount := 0
	root.PreOrderTraverseFunc(func(n *tree.Node) {
		n.Print()
		nodeCount++
	})
	fmt.Println()
	fmt.Println("nodeCount=", nodeCount)
}
